<fieldset id="fd1" style="width:95%;margin:5px;">
	<legend><span>工单信息查询</span></legend>
	<div class="fieldset-body">
		<table class="form-table" border="0" cellpadding="1" cellspacing="2">
			<tr>
				<td class="form-label" style="width:120px;">工单编号:</td>
				<td style="width:120px"><input id="order_no" class="mini-textbox" emptyText="请输入工单编号" style="width:100%;"/></td>
				<td class="form-label" style="width:120px;">售后单编号:</td>
				<td style="width:120px"><input id="order_id" class="mini-textbox" emptyText="请输入备用编号" style="width:100%;"/></td>
				<td class="form-label" style="width:80px;">工单类型:</td>
				<td style="width:120px"><input id="types" class="mini-combobox" textField="name" valueField="id" data="JS.CONST[5]" allowInput="true" style="width:100%;" /></td>
				<td class="form-label" style="width:120px;">派工组织机构:</td>
				<td style="width:120px"><input id="disagency" expandOnLoad="true" class="mini-treeselect" url="/common/agencyOne" multiSelect="false" textField="name" valueField="id" parentField="parent" checkRecursive="true" showFolderCheckBox="true" style="width:100%;"/></td>
				<td style="width:80px;">&nbsp</td>
				<td style="width:150px">&nbsp</td>
			</tr>
			<tr>
				<td class="form-label" style="width:120px;">施工组织机构:</td>
				<td style="width:120px"><input id="conagency" expandOnLoad="true" class="mini-treeselect" url="/common/agencyOne" multiSelect="false" textField="name" valueField="id" parentField="parent" checkRecursive="true" showFolderCheckBox="true" style="width:100%;"/></td>
				<td class="form-label" style="width:80px;">创建时间:</td>
				<td style="width:120px"><input id="createdStart" class="mini-datepicker" value="" style="width:100%"/></td>
				<td class="form-label" style="width:80px;">～</td>
				<td style="width:120px"><input id="createdEnd" class="mini-datepicker" value="" style="width:100%"/></td>
				<td class="form-label" style="width:80px;">工单状态:</td>
				<td style="width:120px"><input id="statuss" class="mini-combobox" textField="name" valueField="id" data="JS.CONST[6]" allowInput="true" style="width:100%;" /></td>
				<td style="width:80px;">&nbsp</td>
				<td style="width:150px"><a class="mini-button" id="search" iconCls="icon-search">查询...</a></td>
			</tr>
		</table>
	</div>
</fieldset>
<div class="mini-toolbar" style="padding:0px;margin:6px 0px 0px 0px;border-bottom:0;width:100%;">
	<table style="width:100%;">
		<tr>
			<td style="width:100%;">
				<a class="mini-button" iconCls="icon-goto" id="buttonOrder" onClick="buttonOrder()" plain="true">编辑备用编号</a>
				<a class="mini-button" iconCls="icon-goto" id="buttonAgency" onClick="buttonAgency()" plain="true">派工到下属组织机构</a>
				<a class="mini-button" iconCls="icon-download" id="buttonStaff" onClick="buttonStaff()" plain="true">派工到员工</a>
				<span class="separator"></span>
				<a class="mini-button" iconCls="icon-undo" id="buttonReturn" onClick="buttonReturn()" plain="true">驳回派工</a>
				<span class="separator"></span>
				<a class="mini-button" iconCls="icon-remove" id="buttonNg" onClick="buttonNg()" plain="true">工单作废</a>
				<span class="separator"></span>
				<a class="mini-button" iconCls="icon-download" onClick="buttonRemove()" plain="true">把已完成工单转备份为历史工单</a>
				<span class="separator"></span>
				<a class="mini-button" iconCls="icon-search" onClick="BusinessInfo('id')" plain="true">查看工单详情</a>
				<span class="separator"></span>
				<a class="mini-button" iconCls="icon-search" onClick="CustomerInfo('customer_id')" plain="true">查看顾客详情</a>
				<span class="separator"></span>
			</td>
		</tr>
	</table>
</div>
<div id="grid1" class="mini-datagrid" allowAlternating="true" frozenStartColumn="0" frozenEndColumn="5" idField="id" pageSize="20" style="width:100%;height:73%;" url="/business/dispatchingList" >
	<div property="columns">
		<div type="checkcolumn" headerAlign="center">选择</div>
		<div field="id" width="80" headerAlign="center" align="center" allowSort="true">工单编号</div>
		<div field="typename" width="80" allowSort="true">工单类型</div>
		<div field="order_id" width="80">售后单编号</div>
		<div field="title" width="120">标题</div>
		<div field="statusname" width="90" headerAlign="center" align="center" allowSort="true">状态</div>
		<!--  
		<div name="action" width="80" headerAlign="center" align="center" renderer="onEdit" cellStyle="padding:0;">操作</div>
		-->
		<div field="customer" width="80">顾客名</div>
		<div header="工单详情" headerAlign="center">
			<div property="columns">
				<div field="content" width="150">详细内容</div>
                <!--
				<div field="business_customer" width="80">业务员</div>
				-->
				<div field="business_customer" width="110" headerAlign="center">创建人(顾客/客服)</div>
				<div field="created" width="140" headerAlign="center" align="center" dateFormat="yyyy-MM-dd HH:mm:ss">创建时间</div>
			</div>
		</div>
		<div header="派工信息" headerAlign="center">
			<div property="columns">
				<div field="dis_agency" width="100">派工组织机构</div>
				<div field="dis_staff" width="80">派工人员</div>
				<div header="派工计划" headerAlign="center">
					<div property="columns">
						<div field="plan_start" width="140" headerAlign="center" align="center" dateFormat="yyyy-MM-dd HH:mm:ss">计划开始时间</div>
						<div field="plan_end" width="140" headerAlign="center" align="center" dateFormat="yyyy-MM-dd HH:mm:ss">计划结束时间</div>
						<div field="plan_work_time" width="60">计划工时</div>
					</div>
				</div>
			</div>
		</div>
		<div header="施工信息" headerAlign="center">
			<div property="columns">
				<div field="con_agency" width="100">施工组织机构</div>
				<div field="con_staff" width="80">施工人员</div>
				<div header="施工计划" headerAlign="center">
					<div property="columns">
						<div field="actual_start" width="140" headerAlign="center" align="center" dateFormat="yyyy-MM-dd HH:mm:ss">实际开始时间</div>
						<div field="actual_end" width="140" headerAlign="center" align="center" dateFormat="yyyy-MM-dd HH:mm:ss">实际结束时间</div>
						<div field="actua_work_time" width="60" headerAlign="center" align="center">实际工时</div>
					</div>
				</div>
			</div>
		</div>
		<!-- 
		<div header="评价信息" headerAlign="center">
			<div property="columns">
				<div field="evaluate" width="40" headerAlign="center" align="center">等分</div>
				<div field="evaluate_content" width="130" headerAlign="center">内容</div>
				<div field="evaluate_time" width="80" headerAlign="center" align="center" dateFormat="yyyy-MM-dd">评价时间</div>
			</div>
		</div>
	    -->
		<div field="remark" width="160" headerAlign="center">备注</div>
	</div>
</div>
<iframe id="exportIFrame" style="display:none;"></iframe>
<script type="text/javascript">
// 初期化
mini.parse();
mini.get("buttonAgency").disable();
mini.get("buttonStaff").disable();
mini.get("buttonReturn").disable();
mini.get("buttonNg").disable();

// 设置编辑路径
var urlDel = "/business/dispatchingDel";
var urlUpd = "/business/dispatchingUpd";

// 取得列表对象
var grid = mini.get("grid1");
grid.load();

// 行选择设定功能状态
grid.on("selectionchanged",function(e){
	var row = grid.getSelected();
	if (row != null) {
		if(row.statuss==1 && (JS.types.indexOf(row.types) >= 0)){
			mini.get("buttonAgency").enable();
		}else{
			mini.get("buttonAgency").disable();
		}

		if(row.statuss==2 && (JS.types.indexOf(row.types) >= 0)){
			mini.get("buttonStaff").enable();
		}else{
			mini.get("buttonStaff").disable();
		}

		if(row.statuss < 4 && row.statuss > 1 && JS.types.indexOf(row.types) >= 0){
			mini.get("buttonReturn").enable();
		}else{
			mini.get("buttonReturn").disable();
		}

		if(row.statuss == 1 && JS.types.indexOf(row.types) >= 0){
			mini.get("buttonNg").enable();
		}else{
			mini.get("buttonNg").disable();
		}
	}
});

// 设置行样式
grid.on("drawcell", function (e) {
	var bgcolor=["","mediumspringgreen","limegreen","lightgreen","darkcyan","olivedrab","orange","peru","tomato","orangered","red"];
	e.cellStyle = "background:" + bgcolor[e.record.statuss];
});

// 查询功能
$("#search").click(function(){
	grid.load({
		    order_no:mini.get("order_no").getValue(),
		    order_id:mini.get("order_id").getValue(),
			types:mini.get("types").getValue(),
			dis_agency_id:mini.get("disagency").getValue(),
			con_agency_id:mini.get("conagency").getValue(),
			created_start:mini.get("createdStart").getText(),
			created_end:mini.get("createdEnd").getText(),
			statuss:mini.get("statuss").getValue()
			});
});

//编辑备用编号
function buttonOrder(){
	var row = grid.getSelected();
	if (row != null) {
		mini.open({
            url: "/business/setOrderShow",
            title: "编辑备用编号", width: 280, height:150,
            onload: function()
            {
                var iframe = this.getIFrameEl();
                var data = {action:"edit",id:row.id,order_id:row.order_id};
                iframe.contentWindow.SetData(data);
            },
            ondestroy:function(action)
            {
            	grid.load({
            		order_no:mini.get("order_no").getValue(),
        		    order_id:mini.get("order_id").getValue(),
        			types:mini.get("types").getValue(),
        			dis_agency_id:mini.get("disagency").getValue(),
        			con_agency_id:mini.get("conagency").getValue(),
        			created_start:mini.get("createdStart").getText(),
        			created_end:mini.get("createdEnd").getText(),
        			statuss:mini.get("statuss").getValue()
        			});
            }
        });
		$(".mini-panel-border .mini-panel-body iframe").css("height","95%");
	} else {
		parent.$.dooDialog.alert("请选中一条记录");
	}
}

// 派工到下属组织机构
function buttonAgency(){
	var row = grid.getSelected();
	if (row != null) {
		mini.open({
            url: "/business/setAgency",
            title: "派工到下属组织机构", width: 530, height:320,
            onload: function()
            {
                var iframe = this.getIFrameEl();
                var data = { action: "edit",id:row.id,types:row.types,remark:row.remark};
                iframe.contentWindow.SetData(data);
            },
            ondestroy:function(action)
            {
            	grid.load({
            		order_no:mini.get("order_no").getValue(),
        		    order_id:mini.get("order_id").getValue(),
        			types:mini.get("types").getValue(),
        			dis_agency_id:mini.get("disagency").getValue(),
        			con_agency_id:mini.get("conagency").getValue(),
        			created_start:mini.get("createdStart").getText(),
        			created_end:mini.get("createdEnd").getText(),
        			statuss:mini.get("statuss").getValue()
        			});
            }
        });
		$(".mini-panel-border .mini-panel-body iframe").css("height","95%");
	} else {
		parent.$.dooDialog.alert("请选中一条记录");
	}
}

//派工到员工
function buttonStaff(){
	var row = grid.getSelected();
	if (row != null) {
		mini.open({
            url: "/business/setStaff",
            title: "派工到员工", width: 530, height:250,
            onload: function()
            {
                var iframe = this.getIFrameEl();
                var data = { action: "edit",id:row.id,remark:row.remark};
                iframe.contentWindow.SetData(data);
            },
            ondestroy:function(action)
            {
            	grid.load({
            		order_no:mini.get("order_no").getValue(),
        		    order_id:mini.get("order_id").getValue(),
        			types:mini.get("types").getValue(),
        			dis_agency_id:mini.get("disagency").getValue(),
        			con_agency_id:mini.get("conagency").getValue(),
        			created_start:mini.get("createdStart").getText(),
        			created_end:mini.get("createdEnd").getText(),
        			statuss:mini.get("statuss").getValue()
        			});
            }
        });
		$(".mini-panel-border .mini-panel-body iframe").css("height","95%");
	} else {
		parent.$.dooDialog.alert("请选中一条记录");
	}
}

//驳回
function buttonReturn(){
	var row = grid.getSelected();
	if (row != null) {
		mini.open({
            url: "/business/setReturn",
            title: "派工驳回", width: 530, height:230,
            onload: function()
            {
                var iframe = this.getIFrameEl();
                var data = { action: "edit",id:row.id,return_content:row.return_content};
                iframe.contentWindow.SetData(data);
            },
            ondestroy:function(action)
            {
            	grid.load({
            		order_no:mini.get("order_no").getValue(),
        		    order_id:mini.get("order_id").getValue(),
        			types:mini.get("types").getValue(),
        			dis_agency_id:mini.get("disagency").getValue(),
        			con_agency_id:mini.get("conagency").getValue(),
        			created_start:mini.get("createdStart").getText(),
        			created_end:mini.get("createdEnd").getText(),
        			statuss:mini.get("statuss").getValue()
        			});
            }
        });
		$(".mini-panel-border .mini-panel-body iframe").css("height","95%");
	} else {
		parent.$.dooDialog.alert("请选中一条记录");
	}
}

//作废工单
function buttonNg(){
	var row = grid.getSelected();
	if (row != null) {
		parent.$.dooDialog.confirm("你确定要把这个工单作废吗？",function(){
			$.post('/business/toStop',{id:row.id,disagency:row.dis_agency_id},function(data){
				if(data.code=='OK'){
					grid.load({
						order_no:mini.get("order_no").getValue(),
					    order_id:mini.get("order_id").getValue(),
						types:mini.get("types").getValue(),
						dis_agency_id:mini.get("disagency").getValue(),
						con_agency_id:mini.get("conagency").getValue(),
						created_start:mini.get("createdStart").getText(),
						created_end:mini.get("createdEnd").getText(),
						statuss:mini.get("statuss").getValue()
						});
				}else{
					parent.$.dooDialog.alert('工单作废失败！');
					return false;
				}
			},'json');
		});
	} else {
		parent.$.dooDialog.alert("请选中一条记录");
	}
}

//备份移除
function buttonRemove(){
	$.post('/business/remove',{id:0},function(data){
		if(data.code=='OK'){
			grid.load({
				order_no:mini.get("order_no").getValue(),
			    order_id:mini.get("order_id").getValue(),
				types:mini.get("types").getValue(),
				dis_agency_id:mini.get("disagency").getValue(),
				con_agency_id:mini.get("conagency").getValue(),
				created_start:mini.get("createdStart").getText(),
				created_end:mini.get("createdEnd").getText(),
				statuss:mini.get("statuss").getValue()
				});
			parent.$.dooDialog.alert('转移成功，需要查看请到[完成工单]菜单！');
		}else{
			parent.$.dooDialog.alert('转移失败！');
			return false;
		}
	},'json');
}
</script>